package com.yjjxt

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Hello09InterSub {
  def main(args: Array[String]): Unit = {
    val sparkContext = new SparkContext((new SparkConf().setMaster("local").setAppName("Join" + System.currentTimeMillis())))
    val array1 = Array[String]("Hello1 user1", "Hello2 user1", "Hello user11", "Hello user12", "user1 apple1", "user orange")
    val array2 = Array[String]("Hello1 user2", "Hello2 user2", "Hello user21", "Hello user22", "user2 apple2", "user orange")
    val lines1 = sparkContext.parallelize(array1, 5)
    val lines2 = sparkContext.parallelize(array2, 4)

    //交集
    val inter: RDD[String] = lines1.intersection(lines2)
    println("交集的分区数" + inter.getNumPartitions)
    inter.foreach(println)

    //差集
    val sub: RDD[String] = lines2.subtract(lines1)
    println("差集的分区数" + sub.getNumPartitions)
    sub.foreach(println)
  }
}
